/**********************************************************************************************/
/* FBL_DTFormat.h      	                                                				 	  */
/*                                                                       					  */
/* Copyright Paradigma, 1993-2006                                       					  */
/* All Rights Reserved.                                                 					  */
/**********************************************************************************************/

#ifndef _FBL_DTFormat_h 
	#define _FBL_DTFormat_h
#pragma once

#include <VShared/FBL/publ/Headers/FBL.h>
#include <VShared/FBL/publ/Utilities/FBL_DateTimeUtilities.h>

#include <stdio.h>

// FINAL:
#include <VShared/FBL/publ/Headers/FBL_pre_header.h>


/**********************************************************************************************/
FBL_Begin_Namespace


/**********************************************************************************************/
// Type that specify format DateTime for database.
//
enum EDateFormat
{
	kMDY	= 0,
	kDMY	= 1,
	kYMD	= 2,
	kMYD	= 3,
	kDYM	= 4,
	kYDM	= 5
};

/**********************************************************************************************/
// Type that specify first day in the week.
//
enum EFirstWeekDay
{
	kSunday = 0,
	kMonday = 1
};


/**********************************************************************************************/
class DTFormat
{
	public:///////////////////////////////////////////////////////////////////////////////////// 

	//----------------------
	// Construction

							DTFormat() :
								mFirstDay( kSunday ),								
								mBound( 20 ),
								mCentury1( 1900 ),
								mCentury2( 2000 ),
								mMaxLength( 32 )
							{
								GetCurrentDateTimeFormat( *this );
							}

virtual						~DTFormat( void ) { }

							
	public:///////////////////////////////////////////////////////////////////////////////////// 
							
		ushort				GetBound( void ) const { return mBound; }	
		void				SetBound( ushort inBound = 20 ) { mBound = inBound; }
				
		tslen				GetMaxLength( void ) const { return mMaxLength; }	
		void				SetMaxLength( tslen inMaxLength = 32 ) { mMaxLength = inMaxLength; }

		void 				GetCentury( ulong& outCentury1, ulong& outCentury2, ushort& outBound ) const
							{
								outCentury1 = mCentury1;
								outCentury2	= mCentury2;
								outBound 	= mBound;
							}	
							
		void				SetCentury( ulong inCentury1 = 1900, ulong inCentury2 = 2000, ushort inBound = 20) 
							{
								FBL_CHECK( inCentury2 - inCentury1 == 100 ); 

								mCentury1 = inCentury1;
								mCentury2 = inCentury2;
								mBound 	  = inBound;
							}
	
							/** Peroforms autocorrection of Year from YY to YYYY format of full year.
								This is comfortable for user. 
								Auto correction works only for year in range 0..99.
								Note, that for negative year there is NO auto correction. 
								You can turn OFF auto correction at all if set mBound to ZERO. */
		void				AutoCentury( long& ioYear ) const
							{		
								if( mBound && 0 <= ioYear && ioYear <= 99 )
								{
									if( ioYear <= mBound )
										ioYear += (long) mCentury2;
									else if( ioYear > mBound )
										ioYear += (long) mCentury1;	
								}
							}


	public:///////////////////////////////////////////////////////////////////////////////////// 

		UChar				mDateSep;		// default is '/'
		UChar				mTimeSep;		// default is ':'
		EDateFormat			mDateFormat;	// default kDMY
		EFirstWeekDay		mFirstDay;		// default is Sunday	

	
	private://////////////////////////////////////////////////////////////////////////////////// 
	
		// The next 3 parameters allow us to do auto-adding of century: YY -> YYYY
		// If these parameters are zero then auto expanding is not performed.
		// This can be used if for historical database.
		
		ushort				mBound;				// default 20			00 => 2000, 20 => 2020
												//						21 => 1921, 99 => 1999
												
		ulong				mCentury1;			// default 1900
		ulong				mCentury2;			// default 2000

		tslen				mMaxLength;			// default 32			"1999-01-01 12:15:16"
};


/**********************************************************************************************/
// This keeps settings default for current system.
// Kernel get them on initialisation.
FBL_SHARED_EXP extern DTFormat* 	gSystemDTFormat;


/**********************************************************************************************/
FBL_End_Namespace

#include <VShared/FBL/publ/Headers/FBL_post_header.h>

#endif // _FBL_DTFormat_h
